using MessagePack;
using Shielded.Gossip;

namespace GossipCore;

public class BrokerSerializer : ISerializer
{
    private static readonly MessagePackSerializerOptions Options =
        MessagePackSerializerOptions.Standard
            .WithResolver(MessagePack.Resolvers.ContractlessStandardResolver.Instance)
            .WithResolver(MessagePack.Resolvers.TypelessContractlessStandardResolver.Instance);

    public byte[] Serialize(object msg)
    {
        return MessagePackSerializer.Serialize(msg, Options);
    }

    public object Deserialize(byte[] bytes)
    {
        return MessagePackSerializer.Deserialize<object>(bytes, Options);
    }
}